package com.gzsxy.Test;

public class Test4 {


    public static void bubbleSort(int[] src) {
        int temp = 0;
        for (int i = 0; i < src.length - 1; i++) {
            for (int j = 0; j < src.length - 1 - i; j++) {
                if (src[j] > src[j + 1]) {
                    temp = src[j];
                    src[j] = src[j + 1];
                    src[j + 1] = temp;
                }
            }
            saymsg(src);
        }
        saymsg(src);
    }


    public static void saymsg(int[] src) {
        for (int i = 0; i < src.length; i++) {
            System.out.print(src[i]);
            System.out.print("  ");
        }
        System.out.println();
    }


    public static void bubble(int[] src) {

        int temp = 0;
        int index = 0;
        //层
        for (int i = 0; i < src.length - 1; i++) {
            //次
            for (int j = 0; j < src.length - 1 - i; j++) {

                if (src[j + 1] < src[j]) {
                    temp = src[j];
                    src[j] = src[j + 1];
                    src[j + 1] = temp;
                }
            }
            System.out.println("第" + index++ + "次循环");
            saymsg(src);
        }
    }


    public static void main(String[] args) {
        int[] src = {49, 38, 65, 97, 76, 13, 27, 49, 78, 34, 12, 64, 5, 4, 62, 99, 98, 54, 56, 17, 18, 23, 34, 15, 35, 25, 53, 51};
        System.out.println("原始数组排序：");
//        saymsg(src);
        bubble(src);
//        shell(src);
    }
}
